﻿using System.Windows.Forms;
using DevExpress.XtraBars.Docking2010.Views.WindowsUI;
using DevExpress.XtraEditors;
using DevExpress.XtraReports.UI;

namespace EduFormManager.Forms.UserControls
{
    public partial class XtraReportViewControl : XtraBaseControl
    {
        private XtraReport _report;
        public XtraReportViewControl(WindowsUIView view) 
            : base(view)
        {
            InitializeComponent();
            this.barButtonItemExport.ItemClick += (sender, args) =>
            {
                FlyoutAction exportAction = new FlyoutAction()
                {
                    Caption = "Экспорт"
                };
                Flyout exportFlyout = View.ContentContainers.FindFirst(t =>
                {
                    Flyout flyout = t as Flyout;
                    if (flyout != null && flyout.Document != null)
                        return "ExportReport".Equals(flyout.Document.ControlName);
                    return false;
                }) as Flyout;
                if (exportFlyout != null)
                {
                    exportFlyout.Action = exportAction;
                    View.ActivateContainer(exportFlyout);
                }
            };
        }

        public XtraReport Report
        {
            set
            {
                _report = value;
                this.documentViewerReport.DocumentSource = value;
            }
        }

        public void ExportToXlsx(string filename)
        {
            _report.ExportToXlsx(filename);
        }

        public void ExportToPdf(string filename)
        {
            _report.ExportToPdf(filename);
        }
    }
}
